<?php
/**
 * @Author: xuzhiyi
 * @Date:   2016-02-23 00:06:06
 * @Last Modified by:   xuzhiyi
 * @Last Modified time: 2016-03-01 14:12:16
 * ------------------------------------------------ *
 * 公共基类                                         *
 * ------------------------------------------------ */
 namespace Home\Model;

use Think\Model;
class CommonModel extends Model {

//用来处理内容中为空的判断

	public function checkEmpty($data){
	    foreach ($data as $key=>$v){
			if(trim($v)==''){
				return false;
			}
		}
		return true;
	}
	

	/* 分页查询
	 * ------------------------*/
    public function PQ($sql,$page = 0,$pageSize = 0){
		$pageSize = (intval($pageSize)==0)?C('PAGE_SIZE'):$pageSize;
		if($pageSize==0)return array();
		$page = (intval($page)<=0)?I(C('VAR_PAGE'),1):intval($page);
		$page = ($page<=0)?1:$page;
		$start = ($page-1)*$pageSize;
		$PQ = array();
		$result = array();
		//查询总数
		$totalSql = "select count(*) counts from (".$sql.") as a";	
		$total = $this->query($totalSql);
		//查询数据		
		$result = $this->query($sql." limit ".$start.",".$pageSize);
		//计算页码信息
		$PQ['total'] = $total[0]['counts'];
		$PQ['pageSize'] = $pageSize;
		$PQ['start'] = $start;
		$PQ['list'] = $result;
		$PQ['totalPage'] = ($PQ['total']%$pageSize==0)?($PQ['total']/$pageSize):(intval($PQ['total']/$pageSize)+1);
		$PQ['currPage'] = $page;
		return $PQ;
    }
}